package com.web44.ssm.interceptor;

import com.web44.ssm.utils.ResponseVo;
import com.web44.ssm.utils.ServletUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Title: ProjectInterceptor
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/16 9:07
 */
@Component
public class ProjectInterceptor implements HandlerInterceptor {

    /**
     * 进入到controller 之前
     * @param request
     * @param response
     * @param handler
     * @return  true  进入到controller  false 不会进入到controller
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println("进入了controller 之前....");
//        ServletUtils.writeResponse(response, ResponseVo.error("尚未授权"));
        return true;
    }

    /**
     * 进入到controller 之后
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("进入了controller 之后....");
    }

    /**
     * 完成
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("完成操作.....");
    }
}
